<#include "/common/_layout.html"/>
<@layout>
<div class="table_box">

	<table id="dg" class="easyui-datagrid" title="上下班详情" style="width:100%;height:750px"
			data-options="rownumbers:true,pagination:true,pageSize:'50',singleSelect:true,url:'list',method:'get',toolbar:toolbar">
		<thead>
			<tr>
				<th data-options="field:'id',hidden:true">id</th>  
				<th data-options="field:'workTime',width:180">下班时间</th>
				<th data-options="field:'duration',width:120">加班时长</th>
				<th data-options="field:'mealAllowanceTimes',width:120">餐补次数</th>
				<th data-options="field:'mealAllowancePrice',width:120">餐补金额</th>
				<th data-options="field:'taxiFare',width:120">的士费</th>
				<th data-options="field:'otherFare',width:120">其他费用</th>
				<th data-options="field:'jobContent',width:240">工作内容</th>
			</tr>
		</thead>
	</table>
	
	<div id="dlg" class="easyui-dialog" title="保存下班信息" style="width:350px;height:400px;padding:10px">
		<form id="ff" method="post" action="add">
			<input type="hidden" id="id" name="mealallowance.id">
	    	<table cellpadding="5">
	    		<tr id="startTimeTr">
	    			<td>上班时间</td>
	    			<td><input class="easyui-datetimebox" type="text" id="startTime" name="mealallowance.startTime"></input></td>
	    		</tr>
	    		<tr>
	    			<td>下班时间:</td>
	    			<td><input class="easyui-datetimebox" type="text" id="workTime" name="mealallowance.workTime" data-options="required:true"></input></td>
	    		</tr>
	    		<tr>
	    			<td>餐补次数:</td>
	    			<td><input class="easyui-textbox" type="text" id="mealAllowanceTimes" name="mealallowance.mealAllowanceTimes" value="1"></input></td>
	    		</tr>
	    		<tr>
	    			<td>餐补金额:</td>
	    			<td><input class="easyui-textbox" type="text" id="mealAllowancePrice" name="mealallowance.mealAllowancePrice" value="25"></input></td>
	    		</tr>
	    		<tr>
	    			<td>交通费:</td>
	    			<td><input class="easyui-textbox" id="taxiFare" name="mealallowance.taxiFare" value="0"></input></td>
	    		</tr>
	    		<tr>
	    			<td>其他费用:</td>
    				<td><input class="easyui-textbox" id="otherFare" name="mealallowance.otherFare" value="0"></input></td>
	    		</tr>
	    		<tr>
	    			<td>工作内容:</td>
    				<td><textarea class="easyui-textarea" id="jobContent" rows="5" name="mealallowance.jobContent"></textarea></td>
	    		</tr>
	    	</table>
	    </form>
	    <div style="text-align:center;padding:5px">
	    	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()">保存</a>
	    	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()">清空</a>
	    	<input type="reset" name="reset" style="display: none;" />
	    </div>
	</div>
	
	<div id="exportExcelDialog" class="easyui-dialog" title="导出excel" style="width:350px;height:220px;padding:10px">
		<form id="exportExcelForm" method="post" action="export">
			<input type="hidden" id="id" name="mealallowance.id">
	    	<table cellpadding="5">
	    		<tr>
	    			<td>开始时间:</td>
	    			<td><input class="easyui-datetimebox" type="text" id="startTime" name="startTime" data-options="required:true"></input></td>
	    		</tr>
	    		<tr>
	    			<td>结束时间:</td>
	    			<td><input class="easyui-datetimebox" type="text" id="endTime" name="endTime" data-options="required:true"></input></td>
	    		</tr>
	    	</table>
	    </form>
	    <div style="text-align:center;padding:5px">
	    	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitExportForm()">确认导出</a>
	    	<input type="reset" name="reset" style="display: none;" />
	    </div>
	</div>
	<script type="text/javascript">
		$(function(){
			$('#dlg').dialog('close');
			$('#exportExcelDialog').dialog('close');
			
			//设置分页控件 
		    var p = $('#dg').datagrid('getPager'); 
		    $(p).pagination({ 
		        pageSize: 50,//每页显示的记录条数，默认为10 
		        pageList: [50,100,200],//可以设置每页记录条数的列表 
		    });
		    
		    //隐藏开始时间输入框
		    $('#startTimeTr').hide();
		    //判断如果是周末，则显示
		    if(new Date().getDay() == 0 || new Date().getDay() == 6)
		    	$('#startTimeTr').show();
		});
		var toolbar = [{
			text:'添加',
			iconCls:'icon-add',
			handler:function(){
				clearForm();
				$('#dlg').dialog('open');
			}
		},{
			text:'修改',
			iconCls:'icon-edit',
			handler:function(){
				var row = $('#dg').datagrid('getSelected');
				if(row) {
					clearForm();
					$.get("getById/" + row.id, function(data, status) {
						$('#id').val(data.id);
						$('#startTime').datetimebox('setValue', data.startTime);
						$('#workTime').datetimebox('setValue',data.workTime);
						$('#mealAllowanceTimes').textbox('setValue',data.mealAllowanceTimes);
						$('#mealAllowancePrice').textbox('setValue',data.mealAllowancePrice);
						$('#taxiFare').textbox('setValue',data.taxiFare);
						$('#otherFare').textbox('setValue',data.otherFare);
						$('#jobContent').val(data.jobContent);
						
						//隐藏开始时间输入框
					    $('#startTimeTr').hide();
					    //判断如果是周末，则显示
					    if(new Date($('#startTime').datebox('getValue')).getDay() == 0 || new Date($('#startTime').datebox('getValue')).getDay() == 6)
					    	$('#startTimeTr').show();
						
						$('#dlg').dialog('open');
					});
				} else {
					$.messager.alert('错误','请选择要修改的行','error');
				}
			}
		},{
			text:'删除',
			iconCls:'icon-remove',
			handler:function(){
				var row = $('#dg').datagrid('getSelected');
				if(row) {
					$.messager.confirm('提示','确定要删除选中的对象吗?',function(r){
					    if (r){
					    	$.get("remove/" + row.id, function(data, status) {
					    		if(data.code === 1) {
									$('#dlg').dialog('close');
									$('#dg').datagrid('reload'); 
								} else {
									$.messager.alert('错误',data.msg,'error');
								}
					    	});
					    }
					});
				} else {
					$.messager.alert('错误','请选择要删除的行','error');
				}
			}
		},'-',{
			text:'导出',
			iconCls:'icon-redo',
			handler:function(){$('#exportExcelDialog').dialog('open');}
		}];
		
		//保存方法
		function submitForm() {
			$('#ff').ajaxSubmit(function (data) {
				if(data.code === 1) {
					$('#dlg').dialog('close');
					$('#dg').datagrid('reload'); 
				} else {
					$.messager.alert('错误','保存失败!','error');
				}
			});
		}
		//清空方法
		function clearForm() {
			$('#ff').form('clear');
			$('#mealAllowanceTimes').textbox('setValue','1');
			$('#mealAllowancePrice').textbox('setValue','25');
			$('#taxiFare').textbox('setValue','0');
			$('#otherFare').textbox('setValue','0');
			$('#jobContent').val('');
		}
		
		//导出excel方法
		function submitExportForm() {
			$('#exportExcelDialog').dialog('close');
			$('#exportExcelForm').submit();
		}
		
	</script>
</div>
</@layout>